<template>
	<view>
		<view class="bg-white padding margin-top" v-if="item">
			<view class="solid-bottom space-between padding-bottom-sm">
				<view class=" text-orange">
					<text v-if="item.is_channel==1">渠道订单</text>
						<text v-if="item.merchant && item.merchant.type==1">门店订单</text>
					<text v-else>零售订单</text>
					<!-- <text>{{item.order_sn}}</text> -->
				</view>
				<view class=" text-red">
					<text v-if="item.order_status == -5" class="text-gray">已删除</text>
					<text v-if="item.order_status == -4" class="text-gray">已取消</text>
					<text v-if="item.order_status == -3" class="text-red">已退款</text>
					<text v-if="item.order_status == -2" class="text-red">退款中</text>
					<text v-if="item.order_status == -1" class="text-red">申请退款</text>
					<text v-if="item.order_status == 0" class="text-red">待付款</text>
					<text v-if="item.order_status == 1" class="text-green">待发货</text>
					<text v-if="item.order_status == 2" class="text-green">待收货</text>
					<text v-if="item.order_status == 3" class="text-green">已收货</text>
					<text v-if="item.order_status == 4" class="text-green">已完成</text>
					<text v-if="item.order_status == 20" class="text-yellow">待审核</text>
					<text v-if="item.order_status == 21" class="text-yellow">驳回</text>
					<text v-if="item.order_status == 101" class="text-brown">拼团中</text>
				</view>
			</view>
			<view class="" v-for="(product,index) in item.product" :key="index" @tap="goPage('/pages/shop/order/detail?id='+item.id)">
				<orderGoods :value="product"></orderGoods>
			</view>
			<view class="text-right padding-tb-sm solid-bottom">
				共<text class="text-black">{{item.product_count}}</text>件商品 实付款<text class="text-price text-red margin-left-xs">{{item.pay_money}}</text>
			</view>
			<view class="text-right margin-top-sm">
				<view class="cu-btn round margin-left-sm line-gray" v-if="item.order_status == -4" @tap="deleteOrder">
					<text class="cuIcon-loading2 cuIconfont-spin" v-if="deleteLoading"></text>
					<text>删除订单</text>
				</view>
				<view class="cu-btn round margin-left-sm line-gray" v-if="item.order_status == 0 || item.order_status == 20" @tap="closeOrder">
					<text class="cuIcon-loading2 cuIconfont-spin" v-if="closeLoading"></text>
					<text>取消订单</text>
				</view>
				<view  v-if="item.order_status == 4 && !item.product[1] && item.product[0].is_evaluate == 0"
				class="cu-btn round margin-left-sm" :class="'line-'+theme" 
				@tap="goPage('/pages/shop/evaluate/create?orderid='+item.id + '&orderproid='+item.product[0].id )">
				我要评价
				</view>
				<view  v-if="item.order_status == 4 && !item.product[1] && item.product[0].is_evaluate == 1"
				class="cu-btn round margin-left-sm" :class="'line-'+theme" 
				@tap="goPage('/pages/shop/evaluate/re_create?type=review&orderid='+item.id )">
				我要追评
				</view>
				<view  v-if="item.order_status == 4 && !item.product[1] && item.product[0].is_evaluate == 2"
				class="cu-btn round margin-left-sm" :class="'line-'+theme" 
				@tap="goPage('/pages/shop/evaluate/create?orderid='+item.id + '&orderproid='+item.product[0].id )">
				查看评价
				</view>
				
				<view  v-if="item.order_status == 4 && item.product[1]" 
				class="cu-btn round margin-left-sm" :class="'line-'+theme" 	@tap="goPage('/pages/shop/evaluate/re_create?type=evaluate&orderid='+item.id)">
				我要评价</view>
				<view class="cu-btn round margin-left-sm" :class="'line-'+theme" @tap="goPage('/pages/shop/order/detail?id='+item.id)">订单详情</view>
				<view class="cu-btn round margin-left-sm" :class="'bg-'+theme" @tap="goPage('/pages/member/wallet/pay?id='+item.id)"
				 v-if="item.order_status == 0">立即支付</view>
			</view>
		</view>

		<serviceView ref="serviceView"></serviceView>
	</view>
</template>

<script>
	import serviceView from '@/components/default/serviceView.vue'
	import orderGoods from '@/components/shop/orderGoods.vue'
	export default {
		components: {
			serviceView,
			orderGoods
		},
		props: {
			item: {
				type: Object,
				default: null,
			}
		},
		created: function(e) {},
		data() {
			return {
				loading: false,
				closeLoading: false,
				deleteLoading: false,
				theme: this.$config.THEME(),
			}
		},
		methods: {
			showService() {
				this.$refs.serviceView.show()
				// window.open('https://uclient.yunque360.com/frame.html?company_id=cjch051hm27mtl')
				// (function() {var _53code = document.createElement("script");_53code.src = "https://tb.53kf.com/code/code/647cfb665881c5ee62274c0e78aaad3b0/1";var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(_53code, s);})();
			},
			deleteOrder() {
				if (this.deleteLoading) return
				this.deleteLoading = true
				uni.showLoading({
					title: '处理中...'
				})
				this.$http
					.delete('order_delete', {
						id: this.item.id
					})
					.then((response) => {
						this.item.order_status = -5
						this.item = null
						console.log(response)
						this.deleteLoading = false
						uni.hideLoading()
						this.$common.showSuccess('处理成功')
					})
					.catch((response) => {
						this.deleteLoading = false
						uni.hideLoading()
					})
			},
			closeOrder() {
				if (this.closeLoading) return
				this.closeLoading = true
				uni.showLoading({
					title: '处理中...'
				})
				this.$http
					.get('order_close', {
						id: this.item.id
					})
					.then((response) => {
						this.item.order_status = -4
						console.log(response)
						this.closeLoading = false
						uni.hideLoading()
						this.$common.showSuccess('处理成功')
					})
					.catch((response) => {
						this.closeLoading = false
						uni.hideLoading()
					})
			},
		},
	}
</script>

<style>
</style>
